package ks.managers.plugin;

import java.net.URL;
import java.util.Date;

/**
 * Entity object representing a Plugin to be played
 * @author harry moreno
 * 
 */
public class Plugin {
	
	/** Name of the plugin */
	public final String name;
	
	/** location of the plugin */
	public final URL location;
//TODO implement date scheme
	/** date of this plugin format: yyyymmddhhmm */
	private String date;
	
	/** status of the plugin: installed, enabled, */
	private boolean suspended;
	
	/** statistics for this plugin */
	private int wins;
	private int losses;
	
	/**
	 * Construct a plugin object given it's name and url
	 * @return 
	 * @parm name		name of the plugin to be created
	 * @parm location	uri of the plugin to be created
	 */
	
	public Plugin(String name, URL loc){
		this.location = loc;
		this.name = name;
		this.suspended = false;
		this.wins = 0;
		this.losses = 0;
		Date now = new Date();
		this.date = now.toString();
	}
	/**
	 * Returns plugins' wins int
	 * @return this.wins	the number of wins on this plugin
	 */
	public int getWins(){
		return this.wins;
	}
	/**
	 * Returns plugin's losses int
	 * @return this.losses	the number of losses on this plugin
	 */
	public int getLosses(){
		return this.losses;
	}
	/**
	 * Returns plugin's status
	 * @return this.suspended	return true if suspended
	 */
	public boolean getSuspended(){
		return this.suspended;
	}
	/**
	 * Returns plugins's name
	 */
	public String getName(){
		return this.name;
	}
	public String getDate(){
		return this.date;
	}
	/**
	 * Sets wins score to given int
	 * only if positive
	 */
	public void setWins(int wins){
		this.wins = wins;
		if (this.wins < 0){
			throw new IllegalArgumentException(
					"wins out of range:" +
					this.wins + " expected range wins >= 0");
		}
	}
	/**
	 * Sets losses score to given int
	 * only if positive
	 */
	public void setLosses(int losses){
		this.losses = losses;
		if (this.losses < 0){
			throw new IllegalArgumentException(
					"losses out of range:" +
					this.losses + " expected range losses >= 0");
		}
	}
	/**
	 * set date value
	 */
	public void setDate(String date){
		this.date = date;
	}
	/**
	 * Sets status to suspended
	 */
	public void suspend(){
		this.suspended = true;
	}
	/**
	 * Sets status to unsuspeded
	 */
	public void unsuspend(){
		this.suspended = false;
	}
}
